package com.websql.yousql.controller;

import com.websql.yousql.service.DBService;
import com.websql.yousql.service.impl.DBServiceImpl;
import com.websql.yousql.entity.Database;
import com.websql.yousql.entity.User;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping({"/db"})
@AllArgsConstructor
public class DBController {
    private final DBService dbService;

    @GetMapping({"/getAll"})
    public List<Database> getAllDB() {
        return this.dbService.getAllDB();
    }

    @GetMapping({"/getUser"})
    public List<User> getUser(String useDatabase) {
        return this.dbService.getAllUser(useDatabase);
    }

    @GetMapping("/getThreadLocal")
    public String getThreadLocal() {
        return DBServiceImpl.threadLocal.get();
    }

}
